package com.testing.control;

import com.testing.soap.SoapInterControl;
import com.testing.utils.ExcelReader;
import com.testing.utils.LoggerConfig;
import com.testing.utils.Utils;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class SoapExcelControl {

    private static String body;

    public static void main(String[] args) {
        Date date = new Date();
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyyMMdd-HH-mm-ss");
        String dates  = simpleDateFormat.format(date);
        ExcelReader excelReader = new ExcelReader("case/soapTestCase.xlsx");
        SoapInterControl soapInterControl = new SoapInterControl("case/soapTestCase.xlsx","case/soapTestCase" + dates + ".xlsx");
        int number = excelReader.getTotalSheetNo(); // 获取当前sheet个数
        for (int i = 0; i < number; i++) {
            LoggerConfig.LOGGER.info("当前sheet的名字：" + excelReader.getSheetName(i));
            // 指定使用的sheet页
            excelReader.useSheetByIndex(i);
            List<String> listCase = new ArrayList<String>();
            for (int j = 0; j < excelReader.rows; j++){
                List<String> line = excelReader.readNextLine();
                // LoggerConfig.LOGGER.info("当前行的内容：" + line);
                soapInterControl.line = j;
                if (Utils.optimization(line.get(0)).length() != 0 || Utils.optimization(line.get(1)).length() != 0){
                    LoggerConfig.LOGGER.info("当前行的内容不是测试用例");
                }else {
                    try {
                        switch (Utils.optimization(line.get(3))){
                            case "createCon":
                                soapInterControl.createCon(Utils.optimization((line.get(4))));
                                break;
                            case "doSoap":
                                body = soapInterControl.testSoap(Utils.optimization(line.get(4)),Utils.optimization(line.get(5)),Utils.optimization(line.get(6)));
                                break;
                            case "saveParam":
                                soapInterControl.saveParam(Utils.optimization(line.get(8)),Utils.optimization(line.get(9)));
                                break;
                            case "addHeader":
                                soapInterControl.addHeader(Utils.optimization(line.get(9)));
                                break;
                        }
                        if ("equals".equals(Utils.optimization(line.get(7)))) {
                            soapInterControl.assertSame(Utils.optimization(line.get(9)), Utils.optimization(line.get(10)));
                        }
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
        excelReader.close();
        soapInterControl.outExcel.save();
    }
}
